g_slist_free (display->cursor_cache);
}
+static gboolean
+set_cursor_from_theme (GdkWaylandCursor *cursor, struct wl_cursor_theme *theme)
+{
+ struct wl_cursor *c;
+
+ c = wl_cursor_theme_get_cursor (theme, cursor->name);
+ if (!c)
+ {
+ g_warning (G_STRLOC ": Unable to load %s from the cursor theme", cursor->name);
+
+ /* return the left_ptr cursor as a fallback */
+ c = wl_cursor_theme_get_cursor (theme, "left_ptr");
+
+ if (!c)
+ return FALSE;
+ }
+
+ cursor->hotspot_x = c->images[0]->hotspot_x;
+ cursor->hotspot_y = c->images[0]->hotspot_y;
+ cursor->width = c->images[0]->width;
+ cursor->height = c->images[0]->height;
+
+ cursor->buffer = wl_cursor_image_get_buffer(c->images[0]);
+ cursor->free_buffer = FALSE;
+
+ return TRUE;
+}
+
+void
+_gdk_wayland_display_update_cursors (GdkWaylandDisplay *display,
+ struct wl_cursor_theme *theme)
+{
+ g_slist_foreach (display->cursor_cache, (GFunc) set_cursor_from_theme, theme);
+}
+
static void
gdk_wayland_cursor_finalize (GObject *object)
{
if (!name || g_str_equal (name, "blank_cursor"))
return GDK_CURSOR (private);
- cursor = wl_cursor_theme_get_cursor (wayland_display->cursor_theme,
- name);
-
- if (!cursor)
- {
- g_warning (G_STRLOC ": Unable to load %s from the cursor theme", name);
-
- /* return the left_ptr cursor as a fallback */
- cursor = wl_cursor_theme_get_cursor (wayland_display->cursor_theme,
- "left_ptr");
-
- /* if the fallback failed to load, return a blank pointer */
- if (!cursor)
- return GDK_CURSOR (private);
- }
+ if (!set_cursor_from_theme (private, wayland_display->cursor_theme))
+ return GDK_CURSOR (private);
/* TODO: Do something clever so we can do animated cursors - move the
* wl_pointer_set_cursor to a function here so that we can do the magic to
* iterate through
*/
- private->hotspot_x = cursor->images[0]->hotspot_x;
- private->hotspot_y = cursor->images[0]->hotspot_y;
- private->width = cursor->images[0]->width;
- private->height = cursor->images[0]->height;
-
- private->buffer = wl_cursor_image_get_buffer(cursor->images[0]);
- private->free_buffer = FALSE;
add_to_cache (wayland_display, private);
display->xkb_context = xkb_context_new (0);
}
+void
+gdk_wayland_display_set_cursor_theme (GdkDisplay *display,
+ const gchar *name,
+ gint size)
+{
+ GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY(display);
+ struct wl_cursor_theme *theme;
+
+ g_assert (wayland_display);
+ g_assert (wayland_display->shm);
+
+ theme = wl_cursor_theme_load (name, size, wayland_display->shm);
+ if (theme == NULL)
+ {
+ g_warning ("Failed to load cursor theme %s\n", name);
+ return;
+ }
+
+ _gdk_wayland_display_update_cursors (wayland_display, theme);
+
+ if (wayland_display->cursor_theme != NULL)
+ wl_cursor_theme_destroy (wayland_display->cursor_theme);
+ wayland_display->cursor_theme = theme;
+}
+
static void
_gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *wayland_display)
{
guint size;
- const gchar *theme_name;
+ const gchar *name;
GValue v = G_VALUE_INIT;
g_assert (wayland_display);
g_value_init (&v, G_TYPE_STRING);
if (gdk_setting_get ("gtk-cursor-theme-name", &v))
- theme_name = g_value_get_string (&v);
+ name = g_value_get_string (&v);
else
- theme_name = "default";
+ name = "default";
- wayland_display->cursor_theme = wl_cursor_theme_load (theme_name,
- size,
- wayland_display->shm);
+ gdk_wayland_display_set_cursor_theme (GDK_DISPLAY (wayland_display),
+ name, size);
g_value_unset (&v);
}